import axios from "axios";
import Vue from 'vue'
import router from "../router/index"

import {config} from "./params"
let $get = (url,params)=>{
    const token = localStorage.getItem("token")
    return new Promise((resolve,reject)=>{
        axios({
            method:'GET',
            url: config.requestUrl+url,
            headers:{
                "Content-Type": "application/x-www-form-urlencoded",
                "Authorization":token
            },
            params:params

        })
        .then((res)=>{
            if(res.data.status===402)
            {
                router.push("/login")
                ElNotification({
                    title: 'ERROR',
                    offset: 100,
                    message: h('i', { style: 'color: teal' }, '身份验证失败，请重新登录！'),
                    type: 'error',
                  })
            }
            else
            resolve(res.data)
        })
        .catch((err)=>{
            console.log(err)
            reject(err)
        })
    })
}
export default{
    install:(app) => {
        Vue.prototype.$get = $get;
      
    }
  }